﻿Imports System
Imports System.Workflow.ComponentModel

Namespace System.Workflow.Activities
    <Serializable> _
    Friend Class StateMachineAction
        ' Methods
        Friend Sub New(ByVal stateName As String)
            Me._stateName = stateName
        End Sub

        Friend Overridable Sub Execute(ByVal context As ActivityExecutionContext)
            If (context Is Nothing) Then
                Throw New ArgumentNullException("context")
            End If
            Me._state = DirectCast(context.Activity, StateActivity)
            Me._currentState = StateMachineHelpers.GetCurrentState(context)
            Dim rootState As StateActivity = StateMachineHelpers.GetRootState(Me._state)
            Me._executionState = StateMachineExecutionState.Get(rootState)
            Me._subscriptionManager = Me._executionState.SubscriptionManager
        End Sub


        ' Properties
        Protected ReadOnly Property CurrentState As StateActivity
            Get
                Return Me._currentState
            End Get
        End Property

        Protected ReadOnly Property ExecutionState As StateMachineExecutionState
            Get
                Return Me._executionState
            End Get
        End Property

        Protected ReadOnly Property State As StateActivity
            Get
                Return Me._state
            End Get
        End Property

        Friend ReadOnly Property StateName As String
            Get
                Return Me._stateName
            End Get
        End Property

        Protected ReadOnly Property SubscriptionManager As StateMachineSubscriptionManager
            Get
                Return Me._subscriptionManager
            End Get
        End Property


        ' Fields
        <NonSerialized> _
        Private _currentState As StateActivity
        Private _executionState As StateMachineExecutionState
        <NonSerialized> _
        Private _state As StateActivity
        Private _stateName As String
        Private _subscriptionManager As StateMachineSubscriptionManager
    End Class
End Namespace

